package cn.tede.file;

import java.io.*;

/*本类用来测试字符输出流*/
public class TestOut2 {
    public static void main(String[] args) {
        method();
        method1();
    }
//有缓冲区
    private static void method1() {
        Writer writer=null;
        try {
            writer=new BufferedWriter(new FileWriter(new File("G:\\IO\\2.txt"),true));
            writer.write("前面的我是你的爷爷");
            System.out.println("BufferedWriter已OVER\n");
        } catch (IOException e) {
            System.out.println("文件异常");
        }finally {
            if (writer!=null){
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
//普通
    private static void method() {
        Writer writer=null;
        try {
            //创建字符流对象
            writer=  new FileWriter("G:\\IO\\2.txt",true);
            //输出字符
            writer.write("我是你爸爸OVER\n");
            System.out.println("FileWriter已over");
        } catch (IOException e) {
            System.out.println("文件位置异常");
        }finally {
            if (writer!=null){
                try {
                    //关闭流
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
